package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * 增强型for循环:新循环
 */
public class NewForDemo {
    public static void main(String[] args) {
        String[] str={"one","two","three","four","five"};
        for (int i=0;i<str.length;i++){
            System.out.println(str[i]);
        }

        //增强for循环
        for(String s : str){
            System.out.println("新循环:"+s);
        }

        Collection c=new ArrayList();
        c.add(1);
        c.add(2);
        c.add(3);
        c.add(4);
        c.add(5);
        Iterator it=c.iterator();
        while (it.hasNext()){
            String str1=(String) it.next();
            System.out.println(str1);
        }

        for(Object obj:c){
            String i=(String) obj;
            System.out.println("新循环:"+i);
        }
    }
}
